<template>
  <div>

    <div
        class="container"
    >
      <div class="image">
        <img :src="/products/+index.img" />
      </div>
      <div class="other">
        <div class="name">{{ index.name }}</div>
        <div class="sketch">
          <span class="important">
           「现在已有{{ index.love }}人想要! 火爆程度{{ index.hot }}!」
          </span>
          <span class="parameter">
            {{ index.description }}
          </span>
          <div class="message1">本家绝活</div>
          <div class="prices">
            <span class="newPrice">{{ index.price }}元</span>
          </div>
          <div class="product-address">
            <ion-icon name="location-outline" class="iconfont"></ion-icon>
            <div  class="address-con">
              <div >
                <div class="address-info">
                  <span >北京</span>
                  <span >北京市</span>
                  <span >海淀区</span>
                  <span >清河街道</span>
                </div>
              <div class="desc">
              </div>
            </div>
            </div></div>
          <div class="separator"></div>
        </div>
        <div class="address"></div>



        <div class="purchase">
          <div class="cart" @click="addToCart">加入购物车</div>
        </div>
        <div class="otherText">
          <ion-icon name="checkmark-circle-outline"></ion-icon><span>美食大餐</span>
          <ion-icon name="checkmark-circle-outline"></ion-icon><span>本家送餐</span>

          <ion-icon name="checkmark-circle-outline"></ion-icon><span>超时说明</span>
          <ion-icon name="checkmark-circle-outline"></ion-icon><span>商家信息</span>
          <br />
        </div>
      </div>
    </div>
    <div class="bottom">
      <div class="text2">价格说明</div>
      <div class="bottomImage">
        <img
            src="/products/bottom.png"
        />
      </div>
    </div>
  </div>
</template>

<script setup>
import { useRoute } from 'vue-router';
import {ref} from "vue";
import {ElMessageBox} from "element-plus";
import router from "../router/index.js";

const route = useRoute();
const index = ref({
  name: '',
  hot: '',
  description:'',
  price:'',
  img:'',
  love:''
})

const detail = JSON.parse(sessionStorage.getItem('externalData')) || [];
index.value = detail.find(product => product.id == route.params.id);
console.log(index.value)
const addToCart = () => {

  if (sessionStorage.getItem('username')) {
    let cart = JSON.parse(sessionStorage.getItem('cart')) || [];

    if (index.value) {
      let index2 = cart.findIndex(item => item.id === route.params.id);
      if (index2 !== -1) {
        cart[index2].count++;
      } else {
        index.value.count = 1;
        cart.push(index.value);
      }

      sessionStorage.setItem('cart', JSON.stringify(cart));
      ElMessageBox.confirm(
          '<ion-icon name="cart-outline"></ion-icon>加入购物车成功！立马去查看',
          '温馨提示',
          {
            confirmButtonText: '迫不及待！',
            cancelButtonText: '我还想要更多',
            type: 'success',
            dangerouslyUseHTMLString: true,
          }
      )
          .then(() => {
            router.push("/User/cart");
          })

    }
  } else {
    ElMessageBox.confirm(
        '您还未登录，是否去登陆？',
        '温馨提示',
        {
          confirmButtonText: '立马去',
          cancelButtonText: '我先看看',
          type: 'warning',
        }
    )
        .then(() => {
          router.push("/login");
        })

  }
}
</script>

<style scoped>
.ItemMessage .messageContainer .otherMsgContainer {
  right: -130px;
}

.ItemMessage .messageContainer .otherMsgContainer #buy {
  display: none;
}

.container {
  width: 1226px;
  height: 600px;
  margin: 0 auto;
  position: relative;
}

.container .image {
  position: absolute;
  top: 32px;
  left: 0px;
  width: 506px;
  height: 560px;
}

.container .image img {
  width: 100%;
  height: 100%;
}

.container .other {
  position: absolute;
  right: 0px;
  width: 601px;
  height: 800px;
}

.container .other .name {
  margin-top: 100px;
  margin-bottom: 25px;
  width: 100%;
  height: 36px;
  color: #212121;
  font-size: 24px;
  font-family: "Helvetica Neue";
}

.container .other .sketch {
  line-height: 21px;
  font-size: 14px;
  font-family: "Helvetica Neue";
}

.container .other .sketch .important {
  color: #ff4a00;
}

.container .other .sketch .parameter {
  color: #b0b0b0;
}

.container .other .sketch .message1 {
  margin-top: 15px;
  font-size: 14px;
  font-family: "Helvetica Neue";
  color: #ff6700;
}

.container .other .sketch .prices {
  margin-top: 10px;
  margin-bottom: 25px;
}

.container .other .sketch .prices .newPrice {
  font-size: 18px;
  color: #ff6700;
}

.container .other .sketch .prices .oldPrice {
  text-decoration: line-through;
  margin-left: 5px;
  font-size: 14px;
  color: #b0b0b0;
}

.container .other .sketch .separator {
  margin-top: 20px;
  margin-bottom: 20px;
  width: 600px;
  height: 1px;
  background-color: #e0e0e0;
}

.container .other .edition {
  width: 600px;
  height: 165px;
}

.container .other .edition .textTips {
  font-size: 18px;
  color: #333;
  font-family: Helvetica;
  font-weight: 400;
}

.container .other .edition .containerSmall {
  width: 600px;
  height: 108px;
}

.container .other .edition .item {
  cursor: pointer;
  margin-top: 10px;
  width: 282px;
  height: 42px;
  padding-right: 5px;
  padding-left: 5px;
  float: left;
  border: 1px solid #e0e0e0;
  text-align: center;
  line-height: 42px;
}

.container .other .edition .item:nth-child(2n-1) {
  margin-right: 10px;
}

.container .other .order {
  width: 600px;
  height: 146px;
  margin-bottom: 40px;
  background-color: #f9f9fa;
  position: relative;
}

.container .other .order .phoneMessage {
  position: absolute;
  top: 35px;
  left: 40px;
  width: 540px;
  height: 30px;
  font-size: 14px;
  font-family: Helvetica;
  color: #616161;
}

.container .other .order .phoneMessage .phonePrice {
  position: absolute;
  right: 0;
  top: 0px;
}

.container .other .order .totalPrice {
  position: absolute;
  top: 100px;
  width: 540px;
  height: 56px;
  font-family: Helvetica;
  top: 80px;
  left: 40px;
  font-size: 24px;
  color: #ff6700;
  text-align: left;
}

.container .other .purchase {
  width: 600px;
  height: 54px;
  margin-bottom: 20px;
}

.container .other .purchase .cart {
  float: left;
  cursor: pointer;
  width: 300px;
  height: 54px;
  background-color: #ff6700;
  font-size: 16px;
  font-family: Helvetica;
  color: #fff;
  text-align: center;
  line-height: 54px;
}

.container .other .purchase .cart:hover {
  background-color: #f25807;
}

.container .other .purchase .like {
  cursor: pointer;
  float: left;
  width: 142px;
  height: 54px;
  margin-left: 10px;
  background-color: #b0b0b0;
  font-size: 16px;
  font-family: Helvetica;
  color: #fff;
  text-align: center;
  line-height: 54px;
}

.container .other .purchase .like .iconfont {
  font-size: 22px;
}

.container .other .purchase .like span {
  position: relative;
  top: -4px;
  left: 5px;
}

.container .other .purchase .like:hover {
  background-color: #757575;
}

.container .other .otherText {
  width: 600px;
  height: 82px;
  font-size: 14px;
  font-family: Helvetica;
  color: #b0b0b0;
  text-align: left;
  line-height: 30px;
}

.container .other .otherText span::after {
  content: "00";
  color: #fff;
  opacity: 0;
}

.container .other .otherText span {
  position: relative;
  top: -2px;
}

.container .other .otherText .iconfont {
  line-height: 30px;
  margin-right: 5px;
  font-size: 20px;
}

.bottom {
  width: 99vw;
  height: 266px;
  padding-bottom: 50px;
  background-color: #f5f5f5;
}

.bottom .text2 {
  text-align: left;
  margin: 0 auto;
  width: 1226px;
  height: 33px;
  padding-top: 22px;
  padding-bottom: 32px;
  font-size: 22px;
  font-family: Helvetica;
  color: #333;
}

.bottom .bottomImage {
  width: 1226px;
  height: 189px;
  margin: 0 auto;
}

.bottom .bottomImage img {
  width: 1226px;
  height: 189px;
}

.active {
  border-color: #ff6700 !important;
  color: #ff6700 !important;}
.temporaryActive {
  border-color: #ff6700 !important;
  color: #ff6700 !important;
}

.product-address{
  padding:30px 50px;
  position:relative;
  background-color: #fafafa;
  border:1px solid #e0e0e0;
}
.iconfont{
  position:absolute;
  left:20px;
  top:26px;
  font-size: 20px;
  color: #999;
}
.address-info{
  display: inline-block;
}
.edit{
  display: inline-block;
}
.info{
  color: #ff6700;
}
</style>